// com.sadam.ui4.FragmentMessagePage.CommentMessage
package com.sadam.ui4.FragmentMessagePage;
import com.sadam.ui4.Data.Video;

public class CommentMessage {
    private String username;
    private String content;
    private long timestamp;
    private String timeAgo;
    private String avatarUrl;
    private String videoTitle;

    // 👇 新增：持有 Video 对象（用于生成封面）
    private Video video;

    public CommentMessage(String username, String content, long timestamp,
                          String avatarUrl, String videoTitle, Video video) {
        this.username = username;
        this.content = content;
        this.timestamp = timestamp;
        this.avatarUrl = avatarUrl;
        this.videoTitle = videoTitle;
        this.video = video; // 保存 Video 对象
        this.timeAgo = calculateTimeAgo(timestamp);
    }

    // Getter
    public String getUsername() { return username; }
    public String getContent() { return content; }
    public long getTimestamp() { return timestamp; }
    public String getTimeAgo() { return timeAgo; }
    public String getAvatarUrl() { return avatarUrl; }
    public String getVideoTitle() { return videoTitle; }
    public Video getVideo() { return video; } // 提供 Video 访问

    // Setter
    public void setTimeAgo(String timeAgo) { this.timeAgo = timeAgo; }

    public void refreshTimeAgo() {
        this.timeAgo = calculateTimeAgo(timestamp);
    }

    public static String calculateTimeAgo(long timestamp) {
        long now = System.currentTimeMillis();
        long diff = now - timestamp;

        long seconds = diff / 1000;
        long minutes = seconds / 60;
        long hours = minutes / 60;
        long days = hours / 24;

        if (minutes < 1) {
            return "刚刚";
        } else if (minutes < 60) {
            return minutes + "分钟前";
        } else if (hours < 24) {
            return hours + "小时前";
        } else if (days < 7) {
            return days + "天前";
        } else {
            java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("M月d日", java.util.Locale.CHINA);
            return sdf.format(new java.util.Date(timestamp));
        }
    }
}